using System;
using System.Collections.Generic;
using System.Text;

namespace SharpMud.Text.Dynamic
{
    /// <summary>
    /// Represents a generic class designed to hold a code object that contains literal code in it that is language-specific
    /// </summary>
    /// <typeparam name="T">Represents the type of language-specific code object we are encapsulating</typeparam>
    public class LanguageBoundCode<T> where T : System.CodeDom.CodeObject, new()
    {
        private T _CodeObject;
        private System.Type _CodeDomProvider;

        private LanguageBoundCode()
        {
        }
        public LanguageBoundCode(T codeObject, System.Type codeDomProvider)
            : this()
        {
            if (codeObject == null)
                throw new ArgumentNullException("The CodeObject cannot be null.");
            _CodeObject = codeObject;
            _CodeDomProvider = codeDomProvider;
        }
        public LanguageBoundCode(T codeObject, System.CodeDom.Compiler.CodeDomProvider codeDomProvider)
        {
            if (codeObject == null)
                throw new ArgumentNullException("The CodeObject cannot be null.");
            _CodeObject = codeObject;
            if (codeDomProvider != null)
                _CodeDomProvider = codeDomProvider.GetType();
        }

        public T CodeObject
        {
            get
            {
                return _CodeObject;
            }
        }

        public System.Type CodeDomProvider
        {
            get
            {
                return _CodeDomProvider;
            }
        }

        public static explicit operator System.CodeDom.CodeObject(LanguageBoundCode<T> val)
        {
            return (System.CodeDom.CodeObject)val._CodeObject;
        }
    }
}
